import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)
// 路由规则数组
const routes = [
  {
    path: '/',
    name: 'layout',
    component: () => import('@/views/layout'),
    children: [
      {
        path: '',
        name: 'home',
        component: () => import('@/views/home'),
      },
      {
        path: 'qa',
        name: 'qa',
        component: () => import('@/views/qa'),
      },
      {
        path: 'video',
        name: 'video',
        component: () => import('@/views/video'),
      },
      {
        path: 'my',
        name: 'my',
        component: () => import('@/views/my'),
      },
    ],
  },
  {
    path: '/login',
    name: 'login',
    // 路由懒加载
    component: () => import('@/views/login'),
  },
  {
    path: '/search',
    name: 'search',
    component: () => import('@/views/search'),
  },
  {
    // 动态路由 根据不同的文章ID展示不同文章的详情
    path: '/article/:articleId',
    name: 'article',
    component: () => import('@/views/article'),
    props: true, // 路由参数映射到组件的props中
  },
  {
    path: '/user/profile',
    name: 'user-profile',
    component: () => import('@/views/user-profile'),
    meta: { needLogin: true }, // 增加一个needLogin用于判断页码是否需要登录
  },
]

const router = new VueRouter({
  routes,
})

export default router
